package com.abxh.jetpack.room.api

import androidx.room.*
import com.abxh.jetpack.room.bean.User
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged

/**
 * Created by dab on 2021/9/2 14:16
 */
@Dao
open interface UserDao {
    @Query("SELECT * FROM users")
    fun getAll(): Flow<List<User>>
    fun getUserDistinctUntilChanged()=getAll().distinctUntilChanged()

    @Query("SELECT * FROM users WHERE uid=(:uid)")
    suspend fun getUserById(uid: Int): User

    @Insert
    suspend fun insertAll(vararg user: User)

    @Delete
    suspend fun delete(vararg user: User)

    @Update
    suspend fun updata(vararg user: User)

    @Query("Delete FROM users WHERE uid=(:uid)")
    suspend fun delete(uid: Int)
}